

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>packnet_sfm.losses.supervised_loss &mdash; PackNet-SfM 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/custom.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../configs/configs.html">Configs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../scripts/scripts.html">Scripts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../trainers/trainers.html">Trainers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../datasets/datasets.html">Datasets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../models/models.html">Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../networks/networks.html">Networks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../losses/losses.html">Losses</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../loggers/loggers.html">Loggers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../geometry/geometry.html">Geometry</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../utils/utils.html">Utils</a></li>
</ul>
<p class="caption"><span class="caption-text">Contact</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://tri.global">Toyota Research Institute</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/TRI-ML/packnet-sfm">PackNet-SfM GitHub</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/TRI-ML/DDAD">DDAD GitHub</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">PackNet-SfM</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>packnet_sfm.losses.supervised_loss</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for packnet_sfm.losses.supervised_loss</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2020 Toyota Research Institute.  All rights reserved.</span>

<span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">import</span> <span class="nn">torch.nn</span> <span class="k">as</span> <span class="nn">nn</span>

<span class="kn">from</span> <span class="nn">packnet_sfm.utils.image</span> <span class="kn">import</span> <span class="n">match_scales</span>
<span class="kn">from</span> <span class="nn">packnet_sfm.losses.loss_base</span> <span class="kn">import</span> <span class="n">LossBase</span><span class="p">,</span> <span class="n">ProgressiveScaling</span>

<span class="c1">########################################################################################################################</span>

<div class="viewcode-block" id="BerHuLoss"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.BerHuLoss">[docs]</a><span class="k">class</span> <span class="nc">BerHuLoss</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Class implementing the BerHu loss.&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">threshold</span><span class="o">=</span><span class="mf">0.2</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes the BerHuLoss class.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        threshold : float</span>
<span class="sd">            Mask parameter</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">threshold</span> <span class="o">=</span> <span class="n">threshold</span>
<div class="viewcode-block" id="BerHuLoss.forward"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.BerHuLoss.forward">[docs]</a>    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pred</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates the BerHu loss.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        pred : torch.Tensor [B,1,H,W]</span>
<span class="sd">            Predicted inverse depth map</span>
<span class="sd">        gt : torch.Tensor [B,1,H,W]</span>
<span class="sd">            Ground-truth inverse depth map</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        loss : torch.Tensor [1]</span>
<span class="sd">            BerHu loss</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">huber_c</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">pred</span> <span class="o">-</span> <span class="n">gt</span><span class="p">)</span>
        <span class="n">huber_c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">threshold</span> <span class="o">*</span> <span class="n">huber_c</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="p">(</span><span class="n">pred</span> <span class="o">-</span> <span class="n">gt</span><span class="p">)</span><span class="o">.</span><span class="n">abs</span><span class="p">()</span>

        <span class="c1"># Remove</span>
        <span class="c1"># mask = (gt &gt; 0).detach()</span>
        <span class="c1"># diff = gt - pred</span>
        <span class="c1"># diff = diff[mask]</span>
        <span class="c1"># diff = diff.abs()</span>

        <span class="n">huber_mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">diff</span> <span class="o">&gt;</span> <span class="n">huber_c</span><span class="p">)</span><span class="o">.</span><span class="n">detach</span><span class="p">()</span>
        <span class="n">diff2</span> <span class="o">=</span> <span class="n">diff</span><span class="p">[</span><span class="n">huber_mask</span><span class="p">]</span>
        <span class="n">diff2</span> <span class="o">=</span> <span class="n">diff2</span> <span class="o">**</span> <span class="mi">2</span>
        <span class="k">return</span> <span class="n">torch</span><span class="o">.</span><span class="n">cat</span><span class="p">((</span><span class="n">diff</span><span class="p">,</span> <span class="n">diff2</span><span class="p">))</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span></div></div>

<div class="viewcode-block" id="SilogLoss"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.SilogLoss">[docs]</a><span class="k">class</span> <span class="nc">SilogLoss</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">Module</span><span class="p">):</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ratio</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">ratio2</span><span class="o">=</span><span class="mf">0.85</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ratio</span> <span class="o">=</span> <span class="n">ratio</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ratio2</span> <span class="o">=</span> <span class="n">ratio2</span>

<div class="viewcode-block" id="SilogLoss.forward"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.SilogLoss.forward">[docs]</a>    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pred</span><span class="p">,</span> <span class="n">gt</span><span class="p">):</span>
        <span class="n">log_diff</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">pred</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ratio</span><span class="p">)</span> <span class="o">-</span> \
                   <span class="n">torch</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">gt</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ratio</span><span class="p">)</span>
        <span class="n">silog1</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">log_diff</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">silog2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ratio2</span> <span class="o">*</span> <span class="p">(</span><span class="n">log_diff</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">silog_loss</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">silog1</span> <span class="o">-</span> <span class="n">silog2</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ratio</span>
        <span class="k">return</span> <span class="n">silog_loss</span></div></div>

<span class="c1">########################################################################################################################</span>

<div class="viewcode-block" id="get_loss_func"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.get_loss_func">[docs]</a><span class="k">def</span> <span class="nf">get_loss_func</span><span class="p">(</span><span class="n">supervised_method</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Determines the supervised loss to be used, given the supervised method.&quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">supervised_method</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;l1&#39;</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">nn</span><span class="o">.</span><span class="n">L1Loss</span><span class="p">()</span>
    <span class="k">elif</span> <span class="n">supervised_method</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;mse&#39;</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">nn</span><span class="o">.</span><span class="n">MSELoss</span><span class="p">()</span>
    <span class="k">elif</span> <span class="n">supervised_method</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;berhu&#39;</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">BerHuLoss</span><span class="p">()</span>
    <span class="k">elif</span> <span class="n">supervised_method</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;silog&#39;</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">SilogLoss</span><span class="p">()</span>
    <span class="k">elif</span> <span class="n">supervised_method</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;abs_rel&#39;</span><span class="p">):</span>
        <span class="k">return</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">y</span><span class="p">)</span> <span class="o">/</span> <span class="n">x</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Unknown supervised loss </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">supervised_method</span><span class="p">))</span></div>

<span class="c1">########################################################################################################################</span>

<div class="viewcode-block" id="SupervisedLoss"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.SupervisedLoss">[docs]</a><span class="k">class</span> <span class="nc">SupervisedLoss</span><span class="p">(</span><span class="n">LossBase</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Supervised loss for inverse depth maps.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    supervised_method : str</span>
<span class="sd">        Which supervised method will be used</span>
<span class="sd">    supervised_num_scales : int</span>
<span class="sd">        Number of scales used by the supervised loss</span>
<span class="sd">    progressive_scaling : float</span>
<span class="sd">        Training percentage for progressive scaling (0.0 to disable)</span>
<span class="sd">    kwargs : dict</span>
<span class="sd">        Extra parameters</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">supervised_method</span><span class="o">=</span><span class="s1">&#39;sparse-l1&#39;</span><span class="p">,</span>
                 <span class="n">supervised_num_scales</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">progressive_scaling</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">loss_func</span> <span class="o">=</span> <span class="n">get_loss_func</span><span class="p">(</span><span class="n">supervised_method</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">supervised_method</span> <span class="o">=</span> <span class="n">supervised_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">supervised_num_scales</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">progressive_scaling</span> <span class="o">=</span> <span class="n">ProgressiveScaling</span><span class="p">(</span>
            <span class="n">progressive_scaling</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>

    <span class="c1">########################################################################################################################</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">logs</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns class logs.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s1">&#39;supervised_num_scales&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">,</span>
        <span class="p">}</span>

<span class="c1">########################################################################################################################</span>

<div class="viewcode-block" id="SupervisedLoss.calculate_loss"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.SupervisedLoss.calculate_loss">[docs]</a>    <span class="k">def</span> <span class="nf">calculate_loss</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inv_depths</span><span class="p">,</span> <span class="n">gt_inv_depths</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculate the supervised loss.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        inv_depths : list of torch.Tensor [B,1,H,W]</span>
<span class="sd">            List of predicted inverse depth maps</span>
<span class="sd">        gt_inv_depths : list of torch.Tensor [B,1,H,W]</span>
<span class="sd">            List of ground-truth inverse depth maps</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        loss : torch.Tensor [1]</span>
<span class="sd">            Average supervised loss for all scales</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># If using a sparse loss, mask invalid pixels for all scales</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">supervised_method</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;sparse&#39;</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">):</span>
                <span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">gt_inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">)</span><span class="o">.</span><span class="n">detach</span><span class="p">()</span>
                <span class="n">inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">mask</span><span class="p">]</span>
                <span class="n">gt_inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">gt_inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">mask</span><span class="p">]</span>
        <span class="c1"># Return per-scale average loss</span>
        <span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">loss_func</span><span class="p">(</span><span class="n">inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">gt_inv_depths</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">)])</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span></div>

<div class="viewcode-block" id="SupervisedLoss.forward"><a class="viewcode-back" href="../../../losses/losses.supervised_loss.html#packnet_sfm.losses.supervised_loss.SupervisedLoss.forward">[docs]</a>    <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inv_depths</span><span class="p">,</span> <span class="n">gt_inv_depth</span><span class="p">,</span>
                <span class="n">return_logs</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">progress</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates training supervised loss.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        inv_depths : list of torch.Tensor [B,1,H,W]</span>
<span class="sd">            Predicted depth maps for the original image, in all scales</span>
<span class="sd">        gt_inv_depth : torch.Tensor [B,1,H,W]</span>
<span class="sd">            Ground-truth depth map for the original image</span>
<span class="sd">        return_logs : bool</span>
<span class="sd">            True if logs are saved for visualization</span>
<span class="sd">        progress : float</span>
<span class="sd">            Training percentage</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        losses_and_metrics : dict</span>
<span class="sd">            Output dictionary</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># If using progressive scaling</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">progressive_scaling</span><span class="p">(</span><span class="n">progress</span><span class="p">)</span>
        <span class="c1"># Match predicted scales for ground-truth</span>
        <span class="n">gt_inv_depths</span> <span class="o">=</span> <span class="n">match_scales</span><span class="p">(</span><span class="n">gt_inv_depth</span><span class="p">,</span> <span class="n">inv_depths</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">,</span>
                                     <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;nearest&#39;</span><span class="p">,</span> <span class="n">align_corners</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="c1"># Calculate and store supervised loss</span>
        <span class="n">loss</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">calculate_loss</span><span class="p">(</span><span class="n">inv_depths</span><span class="p">,</span> <span class="n">gt_inv_depths</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_metric</span><span class="p">(</span><span class="s1">&#39;supervised_loss&#39;</span><span class="p">,</span> <span class="n">loss</span><span class="p">)</span>
        <span class="c1"># Return losses and metrics</span>
        <span class="k">return</span> <span class="p">{</span>
            <span class="s1">&#39;loss&#39;</span><span class="p">:</span> <span class="n">loss</span><span class="o">.</span><span class="n">unsqueeze</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span>
            <span class="s1">&#39;metrics&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">metrics</span><span class="p">,</span>
        <span class="p">}</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Toyota Research Institute (TRI)

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(false);
      });
  </script>

  
  
    
   

</body>
</html>